<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
                com.scalar.ScalarException,
                com.scalar.chiptrack.operations.process.BinSetup,
                com.scalar.chiptrack.operations.process.dao.BinSetupDAO,
                com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<!--chiptrack:checkLogon sourcePage="/jsp/operations/test_bin_setup.jsp"/-->
<chiptrack:checkLogon sourcePage="/baseProductList.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<html:html locale="true">

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type='text/css' rel='stylesheet'>

<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>

<SCRIPT>
function saveBins() 
{
    var errors = ''; 
	var index = "";

	for ( var x=0 ; x < document.testBinSetupForm.partNumber.length ; x++ ) 
	{
		document.testBinSetupForm.partNumber[x].value = document.testBinSetupForm.partNumber[x].value.trim() ;
	}

	for ( var x=0 ; x < document.testBinSetupForm.partNumber.length -1 ; x++ ) 
	{
		for ( var y = x+1 ; y < document.testBinSetupForm.partNumber.length ; y++ ) 
		{
			if( document.testBinSetupForm.partNumber[x].value != ""  && document.testBinSetupForm.partNumber[x].value.trim().length > 0 )
			{
				if(document.testBinSetupForm.partNumber[x].value== document.testBinSetupForm.partNumber[y].value)
				{
					errors =  "<li> Two part numbers cannot be same";
					index = y;
				}
			}
		}
	}
	for ( var x=0 ; x < document.testBinSetupForm.partNumber.length ; x++ ) 
	{
		var temp = "binType"+x+"[0]";
		var temp1 = "binType"+x+"[1]";
			
		if( eval("document.testBinSetupForm."+temp).checked=="1" || eval("document.testBinSetupForm."+temp1).checked=="1" )
		{
			if( document.testBinSetupForm.partNumber[x].value == '' || document.testBinSetupForm.partNumber[x].value.trim().length == 0 )
			{
				errors =  "<li> part number cannot be empty for Good or Reject type";
				index = x;
			}
		}
	}

	if(errors != '')
	{
		var pa=document.getElementById("errors");
		pa.innerHTML = errors;
		document.testBinSetupForm.partNumber[index].focus();
		return;
	}
	else
	{
		for ( var y=0; y < document.testBinSetupForm.partNumber.length; y++ ) 
		{
			var temp = "binType"+y+"[0]";
			var temp1 = "binType"+y+"[1]";
			var temp2 = "binType"+y+"[2]";
			eval("document.testBinSetupForm."+temp).disabled = false;
			eval("document.testBinSetupForm."+temp1).disabled = false;
			eval("document.testBinSetupForm."+temp2).disabled = false;

		}
	}

	/*for ( var y=0; y < document.testBinSetupForm.partNumber.length; y++ ) 
	{
		var temp = document.testBinSetupForm.mark_Pack_ProcessStep_ID[y].value;
		if( temp != "-1" && temp != "-2")
		{
			if( document.testBinSetupForm.partNumber[y].value.trim().length == 0 )
			{
				document.testBinSetupForm.partNumber[y].value = document.testBinSetupForm.oldPartNumber[y].value;
				errors =  "<li> Part number cannot be Rejected or NA for already ";
				index = x;
			}
		}
	}*/
	
	
	document.testBinSetupForm.submit();
}

function newBins() {
    var count = document.testBinSetupForm.count.value
    var htmltext1 = '<table><tr><td width="10%" align="center" bgcolor="#CCCCCC"><font class="NArialL">Bin' + (count) + '</font></td><input type="hidden" name="binNo" value="Bin'+(count)+'"><input type="hidden" name="mark_Pack_ProcessStep_ID" value="-1"><input type="hidden" name="fG_ProcessStep_ID" value="-1"><td width="35%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="radio" name="binType' + (count-1) + '" value="Accept">Good&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="Reject">Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="N/A" checked>NA</font></td><td width="17%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="text" name="partNumber" align="center" class="txfield" value="" size="14" maxlength="50"><input type="hidden" name="oldPartNumber" value="" ></font><td width="8%" align="center" bgcolor="#CCCCCC"><input type="text" name="yield" value="0.0" align="center" class="txfield" size="10" maxlength="10"></font></td><td width="30%" align="center" bgcolor="#CCCCCC"><input type="text" name="binDescription" align="center" class="txfield" value="   Bin' + (count++) + ' Description" size="20"></td></tr><tr><td width="10%" align="center" bgcolor="#CCCCCC"><font class="NArialL">Bin' + (count) + '</font></td><input type="hidden" name="binNo" value="Bin'+(count)+'"><input type="hidden" name="mark_Pack_ProcessStep_ID" value="-1"><input type="hidden" name="fG_ProcessStep_ID" value="-1"><td width="35%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="radio" value="Accept" name="binType' + (count-1) + '">Good&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="Reject">Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="N/A" checked>NA</font></td><td width="17%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="text" name="partNumber" align="center" class="txfield" value="" size="14" maxlength="50"><input type="hidden" name="oldPartNumber" value="" ></font><td width="8%" align="center" bgcolor="#CCCCCC"><input type="text" name="yield" value="0.0" align="center" class="txfield" size="10" maxlength="10"></font></td><td width="30%" align="center" bgcolor="#CCCCCC"><input type="text" name="binDescription" align="center" class="txfield" value="   Bin' + (count++) + ' Description" size="20"></td></tr>    <tr><td width="10%" align="center" bgcolor="#CCCCCC"><font class="NArialL">Bin' + (count) + '</font></td><input type="hidden" name="binNo" value="Bin'+(count)+'"><input type="hidden" name="mark_Pack_ProcessStep_ID" value="-1"><input type="hidden" name="fG_ProcessStep_ID" value="-1"><td width="35%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="radio" value="Accept" name="binType' + (count-1) + '">Good&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="Reject">Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="N/A" checked>NA</font></td><td width="17%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="text" name="partNumber" align="center" class="txfield" value="" size="14" maxlength="50"><input type="hidden" name="oldPartNumber" value="" ></font><td width="8%" align="center" bgcolor="#CCCCCC"><input type="text" name="yield" value="0.0" align="center" class="txfield" size="10" maxlength="10"></font></td><td width="30%" align="center" bgcolor="#CCCCCC"><input type="text" name="binDescription" align="center" class="txfield" value="   Bin' + (count++) + ' Description" size="20"></td></tr><tr><td width="10%" align="center" bgcolor="#CCCCCC"><font class="NArialL">Bin' + (count) + '</font></td><input type="hidden" name="binNo" value="Bin'+(count)+'"><input type="hidden" name="mark_Pack_ProcessStep_ID" value="-1"><input type="hidden" name="fG_ProcessStep_ID" value="-1"><td width="35%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="radio" value="Accept" name="binType' + (count-1) + '">Good&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="Reject">Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="binType' + (count-1) + '" value="N/A" checked>NA</font></td><td width="17%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><input type="text" name="partNumber" align="center" class="txfield" value="" size="14" maxlength="50"><input type="hidden" name="oldPartNumber" value="" ><td width="8%" align="center" bgcolor="#CCCCCC"><input type="text" name="yield" value="0.0" align="center" class="txfield" size="10" maxlength="10"></font></td></font><td width="30%" align="center" bgcolor="#CCCCCC"><input type="text" name="binDescription" align="center" class="txfield" value="   Bin' + (count++) + ' Description" size="20"></td></tr>  </table>'
    var pa1=document.getElementById("font1");
    pa1.insertAdjacentHTML('BeforeEnd',htmltext1);
    document.testBinSetupForm.count.value = count;
}

function back(){
      window.location = '<%=chipTracContext%>/processView.do?action=true&productID='+document.testBinSetupForm.baseProductId.value;
}
</SCRIPT>
</HEAD>
<BODY bgColor='#ffffff' leftMargin='0' topMargin='0' marginheight='0' marginwidth='0'>
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@ include file="/jsp/operations/operations_menu.jsp" %>

	</TD>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->

<center><span class="NArialW">Test Bin Information</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>

<html:form name="testBinSetupForm" type="com.scalar.chiptrack.ChipTrackActionForm" action="/testBinSetup.do?action=save">
<input type="hidden" name="baseProductId" value='<%=session.getAttribute("baseProductId")%>'>
    <table border="0" width="90%" align=right>
    <a name="#top"/>
	<tr><td colspan=5 class="NArialL" align="left"><font color="FF0000"><FONT id="errors"></FONT></font></TD></TR>
    <tr><td colspan='5'><chiptrack:errors styleClass='NArialL'/></td></tr>
      <tr><td colspan=5 class="NArialL"><img src="<%=chipTracContext%>/jsp/includes/images/exclamation-46x47.gif" height=25><font color="#0000FF">Disabled rows TYPE indicates configuration finished in Mark & Pack stage</font></td></tr>
      <tr><td colspan=5>
      <table border="0" width="90%" bordercolor="#FFFFFF">

    <tr>
        <td width="10%" bgcolor="#993333" align="center"><font class="NArialL"><font color="#FFFFFF">Bin Number</font></td>
        <td width="35%" bgcolor="#993333" align="center"><font class="NArialL"><font color="#FFFFFF">Type</font></td>
	<td width="17%" bgcolor="#993333" align="center"><font class="NArialL"><font color="#FFFFFF">Part Number</font></td>
        <td width="8%" bgcolor="#993333" align="center"><font class="NArialL"><font color="#FFFFFF">Yield</font></td>
        <td width="30%" bgcolor="#993333" align="center"><font class="NArialL"><font color="#FFFFFF">Description</font></td>
    </tr>

    <%
        int processStepId = Integer.parseInt ((String) session.getAttribute ("processStepId"));
        int oldProcessStepId = Integer.parseInt ((String) session.getAttribute ("oldProcessStepId"));

	// This Part of the code is being transfered to TransportAction
	// Commented by Ravikanth on 27 Aug 2003
	/*	ArrayList binList = null;
        try {
            if (oldProcessStepId != -1) {
                binList = BinSetupDAO.loadBins (oldProcessStepId);
            }
            else {
                binList = BinSetupDAO.loadBins (processStepId);
            }
        }
        catch (ScalarException se) {
            System.out.println ("Exception while loading bin information: " + se.getRootCause());
        } */

		ArrayList binList =  (ArrayList)request.getAttribute("binList");
        
		if ((binList != null) && (binList.size() != 0)) {
			
            //BinSetup binSetup = null;
            //String binNumber = null;
            //String binType = null;
            //String partNumber = null;
            //String description = null;
           // float binYield = 0.0f;

            int size = binList.size();
    %>
        <input type=hidden name=count value='<%=(size+1)%>' >
    <!-- cut from here -->
	<logic:iterate name="binList" scope="request" indexId="xx" id="binSetUp" type="com.scalar.chiptrack.operations.process.BinSetup" >
	    <tr>
			<td width="10%" align="center" bgcolor="#CCCCCC"><font class="NArialL"><bean:write name="binSetUp" property="binNo"/></font></td>
			<html:hidden property="binNo" name="binSetUp"  /> <!-- added a new Hidden Field -->
			<html:hidden name="binSetUp" property="mark_Pack_ProcessStep_ID"/>
			<input type="hidden" name="fG_ProcessStep_ID" value="<%=binSetUp.getFG_ProcessStep_ID()%>">
			<% if( binSetUp.getMark_Pack_ProcessStep_ID().equals("-1") || binSetUp.getMark_Pack_ProcessStep_ID().equals("-2")){ %>

			<td width="35%" align="center" bgcolor="#CCCCCC"><font class="NArialL">
			<input type="radio" name="<%= ("binType" + xx) %>" value="Accept" <%if (BinSetup.TYPE_ACCEPT.equalsIgnoreCase (binSetUp.getBinType())) out.print ("checked");%> ><font class="NArialL">Good &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="<%= ("binType" + xx) %>" value="Reject" <%if (BinSetup.TYPE_REJECT.equalsIgnoreCase (binSetUp.getBinType())) out.print ("checked");%> >Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="<%= ("binType" + xx) %>" value="N/A"    <%if (BinSetup.TYPE_NA.equalsIgnoreCase (binSetUp.getBinType())) out.print ("checked");%> >NA</font>
			</td>
			<% } else { %>
			<td width="35%" align="center" bgcolor="#CCCCCC"><font class="NArialL">
			<input type="radio" name="<%= ("binType" + xx) %>" value="Accept" <%if (BinSetup.TYPE_ACCEPT.equalsIgnoreCase (binSetUp.getBinType())) out.print ("checked");%>  DISABLED ><font class="NArialL">Good &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="<%= ("binType" + xx) %>" value="Reject" <%if (BinSetup.TYPE_REJECT.equalsIgnoreCase (binSetUp.getBinType())) out.print ("checked");%>  DISABLED >Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="<%= ("binType" + xx) %>" value="N/A"    <%if (BinSetup.TYPE_NA.equalsIgnoreCase (binSetUp.getBinType())) out.print ("checked");%>  DISABLED >NA</font>
			</td>
			<%}%>

			<td width="17%" align="center" bgcolor="#CCCCCC">
				<html:text name="binSetUp" property="partNumber"  styleClass="txfield" size="14" maxlength="50"/>
				<html:hidden  name="binSetUp" property="oldPartNumber"/>
			</td>
			<td width="8%" align="center" bgcolor="#CCCCCC">
				<html:text name="binSetUp" property="yield" styleClass="txfield" size="10" maxlength="10"/>
			</td>
			<td width="30%" align="center" bgcolor="#CCCCCC">
				<html:text name="binSetUp" property="binDescription" styleClass="txfield" size="20"/>
			</td>
		</tr>
	</logic:iterate>
    <%
            
        }
        else {
		
    %>
    <input type=hidden name=count value=11>
	<% for ( int i=0; i < 10 ; i++ ){ %>
    <tr>
        <td width="10%" align="center" bgcolor="#CCCCCC"><font class="NArialL">Bin<%=i+1%></font></td>
		<input type="hidden" name="binNo" value="Bin<%=i+1%>" >
		<input type="hidden" name="mark_Pack_ProcessStep_ID" value="-1" >
		<input type="hidden" name="fG_ProcessStep_ID" value="-1" >
        <td width="35%" align="center" bgcolor="#CCCCCC">
            <input type="radio" name="binType<%=i%>" value="Accept"><font class="NArialL">Good &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="binType<%=i%>" value="Reject">Reject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="binType<%=i%>" value="N/A" checked>NA</font></td>
        <td width="17%" align="center" bgcolor="#CCCCCC">
            <input type="text" name="partNumber" align="center" class="txfield" size="14"  maxlength="50">
			<input type="hidden" name="oldPartNumber"></font></td>
        <td width="8%" align="center" bgcolor="#CCCCCC">
            <input type="text" name="yield" value="0.0" align="center" class="txfield" size="10" maxlength="10"></font></td>
        <td width="30%" align="center" bgcolor="#CCCCCC">
            <input type="text" name="binDescription" align="center" class="txfield" value="   Bin<%=i+1%> Description" size="20"></font></td>
      </tr>
	  <% } // end of for loop %>	

      <%
      }   // else block
      %>

      <tr><td colspan=5><font id="font1"></font></td></tr>

    	  <tr><td colspan=4>&nbsp;</td></tr>
		  <tr>
		    <td align=center colspan=4>
                        <!--a href="javascript:newBins()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/addmore.gif"></a-->
                        <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:newBins();' onmouseover="window.status='Click here to Add new Bins';return true" onmouseout="window.status='';return true">
                        <img border='0' src='<%=chipTracContext%>/jsp/includes/images/addmore.gif'></chiptrack:restrictedLink>
                     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                   	    <!--a href="javascript:saveBins()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif"></a-->
                        <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:saveBins();' onmouseover="window.status='Click here to save this Bins';return true" onmouseout="window.status='';return true">
                        <img border='0' src='<%=chipTracContext%>/jsp/includes/images/next.gif'></chiptrack:restrictedLink>
                     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		                <!--a href="<%=chipTracContext%>/jsp/operations/test_process.jsp"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif"></a-->
                        <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:back();' onmouseover="window.status='Click here to go back to Process View';return true" onmouseout="window.status='';return true">
                        <img border='0' src='<%=chipTracContext%>/jsp/includes/images/cancel.gif'></chiptrack:restrictedLink></a>
     		</td></tr>
	    </table>

      </td></tr>
    </table>

</html:form>

<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</body>

</html:html>
